package com.sctvcloud.longchang.ui.adapter;

import android.content.Context;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.sctvcloud.longchang.R;
import com.sctvcloud.longchang.base.BaseActivity;
import com.sctvcloud.longchang.base.BaseFragment;
import com.sctvcloud.longchang.ui.adapter.holder.BaseAbsHolder;
import com.sctvcloud.longchang.ui.adapter.holder.Hour24TitleHolder;
import com.sctvcloud.longchang.ui.adapter.holder.LetterIndexHolder;
import com.sctvcloud.longchang.ui.adapter.holder.News24Holder;
import com.sctvcloud.longchang.ui.adapter.holder.TelLetterHolder;
import com.sctvcloud.longchang.ui.adapter.holder.TelephoneHolder;
import com.sctvcloud.longchang.ui.util.IListShowData;

import java.util.ArrayList;
import java.util.List;

/**
 * 电话页面适配
 */
public class TelephoneListAdapter extends BaseHolderAbsAdapter<IListShowData, BaseAbsHolder<IListShowData>> {

    public static final int VIEWTYPE_LETTER = 1;//显示电话名称的首字母
    public static final int VIEWTYPE_TELEPHONE = 2;//电话
    public static final int VIEWTYPE_LETTER_INDEX = 3;//右侧首字母索引

   private LetterIndexHolder.OnLetterClickLister listener;
   private TelephoneHolder.OnTelephoneClickListener onTelephoneClickListener;

    public TelephoneListAdapter(Context context, List<IListShowData> list) {
        super(context, list);
    }

    @Override
    public BaseAbsHolder<IListShowData> onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseAbsHolder bah = null;
        View v = null;
        switch (viewType) {
            case VIEWTYPE_LETTER://
                v = LayoutInflater.from(context).inflate(R.layout.item_tel_letter, parent, false);
                bah = new TelLetterHolder(context, v);
                break;
            case VIEWTYPE_LETTER_INDEX://
                v = LayoutInflater.from(context).inflate(R.layout.item_tel_letter_index, parent, false);
                bah = new LetterIndexHolder(context, v,listener);
                break;
            case VIEWTYPE_TELEPHONE://
            default:
                v = LayoutInflater.from(context).inflate(R.layout.item_telephone, parent, false);
                bah = new TelephoneHolder(context, v,onTelephoneClickListener);
                break;
        }
        return bah;
    }

    @Override
    public int getItemViewType(int position) {
        return data.get(position).getDataViewType();
    }

    @Override
    public void onBindViewHolder(BaseAbsHolder<IListShowData> holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.setItemMode(position == getItemCount() - 1 ? BaseAbsHolder.ITEMMODE_LAST : BaseAbsHolder.ITEMMODE_NORMAL);
    }

    /**
     * 设置右侧字母索引的点击
     * @param listener
     */
    public void setOnLetterClickListener(LetterIndexHolder.OnLetterClickLister listener) {
        this.listener = listener;
    }

    /**
     * 电话簿点击
     * @param onTelephoneClickListener
     */
    public void setOnTelephoneClickListener(TelephoneHolder.OnTelephoneClickListener onTelephoneClickListener) {
        this.onTelephoneClickListener = onTelephoneClickListener;
    }
}
